//
//  YDBottomPageView.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/18.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit
private let YDBottomPageViewCellID = "YDBottomPageViewCellID"
class YDBottomPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
//        设置flowlayout是因为他有indexpath
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func setupUI(){
//    注册cell
        registerClass(YDEmotionPageCell.self, forCellWithReuseIdentifier: YDBottomPageViewCellID)
//        设置代理
        dataSource = self
    }
    override func layoutSubviews() {
        super.layoutSubviews()
//        设置layout
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
//        设置itemsize
        layout.itemSize = self.frame.size
//        设置水平垂直间距
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        layout.scrollDirection = .Horizontal
        
    }
}
extension YDBottomPageView:UICollectionViewDataSource{
    
     func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return YDEmoticonTools.shareTools.allEmoticons.count
    }
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return YDEmoticonTools.shareTools.allEmoticons[section].count
        
    }
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(YDBottomPageViewCellID, forIndexPath: indexPath) as! YDEmotionPageCell
        cell.backgroundColor = randomColor()
        cell.indexpath = indexPath
//        赋值给button图片数组
        cell.emotions = YDEmoticonTools.shareTools.allEmoticons[indexPath.section][indexPath.item]
        cell.backgroundColor = self.backgroundColor
        return cell
    }

}